<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head th:replace="common/header::common_head"></head>
<title>条码管理</title>
<body class="hold-transition skin-blue sidebar-mini">
<div th:replace="common/LeftCommon::common_top_left"></div>
<style type="text/css">
    .single-pannel .row-title{
        border-bottom:1px dashed #ddd;
        font-weight:bold;
        margin:0px 20px 20px 10px;
        text-align:left;
    }

    .text-dark{
        width: 110px;
        display: inline;
        height: 32px;
        padding: 5px 6px;
        font-size: 14px;
        color: #222;
        border: 1px solid #ccc;
        border-radius: 0;
        box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        display: inline;
        background-color: rgb(223,223,223);
    }
</style>
<div class="wrapper">
<div class="content-wrapper" style="min-height: 901px;">
    <div class="single-pannel">
        <form class="form-horizontal ng-valid ng-dirty" id="editForm" name="editForm" novalidate="novalidate">
            <section class="content-header">
                <h1>
                    条码管理
                    <small>BarCodeManagement</small>
                </h1>
                <ol class="breadcrumb">
                    <li><a href="/index"><i class="fa fa-dashboard"></i>首页</a></li>
                    <li><a href="#"></a>商品设置</li>
                    <li class="active">条码管理</li>
                </ol>
            </section>

            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <h2>条码配置</h2>
                            </div>
                            <hr style=" height:2px;border:none;border-top:2px dotted #575757;">
                            <div ng-show="!loading">
                                <br>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">自动生成条码</label>
                                    <div class="col-sm-5" style="line-height: 34px;">
                                        <label class="sel-a" style="margin-bottom: 0px; font-weight: normal;"> <input type="checkbox" id="static"> 启用
                                        </label> <span class="tips-text" style="display: block; line-height: 18px;">启用后在新建或编辑商品时将自动生成条码</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">自动生成项</label>
                                    <div class="col-sm-5" style="line-height: 34px;">
                                        <label class="sel-a" style="margin-bottom: 0px; font-weight: normal;"><input type="radio" name="barcodeItem" value="1" >商品条码&nbsp;&nbsp;</label>
                                        <label class="sel-a" style="margin-bottom: 0px; font-weight: normal;"><input type="radio" name="barcodeItem" value="2" >单品条码</label>
                                        <span class="tips-text" style="display: block; line-height: 18px;">选择商品条码后，在新建商品、补充无条码商品、重置所有商品条码时将只对商品条码有效；选择单品条码后，在新建商品、补充无条码商品、重置所有商品条码时将只对单品条码有效；</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">条码类型</label>
                                    <div class="col-sm-5" style="line-height: 34px;">
                                        <select><option value="ean13">EAN-13</option></select> <span class="tips-text" style="display: block; line-height: 18px;">EAN-13码由8位厂商识别代码、4位产品代码及1位校验码组成。厂商识别码由企业向国家物品编码中心申请取得；产品代码可由企业自己定义（4位产品代码0000~9999
								适用于1万种产品）；1位校验码可以由前面12位确定后计算出来。</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">条码格式</label>
                                    <div class="col-sm-5 float:left">
                                        <input type="number" onkeyup="number()" onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode) ) )' class="form-control" style="width: 140px; display: inline;"  id="factoryCode" name="factoryCode" min="0" max="99999999" placeholder="8位厂商识别码">&nbsp;-&nbsp;
                                        <div class="text-dark"><nobr>4位产品代码(系统生成)</nobr></div>
                                        &nbsp;-&nbsp;
                                        <div class="text-dark"><nobr>1位校验码(系统生成)</nobr></div>
                                        <span class="tips-text" style="display: block; line-height: 18px;">厂商识别码由用户输入，产品代码将由系统从0000至9999中顺序生成，1位校验码将由系统根据厂商识别码及产品代码计算得出。</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">产品代码起始值</label>
                                    <div class="col-sm-5">
                                        <input type="number" onkeyup="number()" onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode) ) )' style="width: 200px;" class="form-control" id="startCode" name="startCode" min="0" max="9999" placeholder="请输入产品代码起始值...">
                                        <span class="tips-text" style="display: block; line-height: 18px;">产品起始值设置后，系统生成条码时产品代码将从此起始值开始顺序生成，如设置了厂商识别码为69012345，起始值为1234,则系统下一个生成的条码为6901234512359(最后一位9由前面12位计算得出)，如果系统已存在大于这个条码值的条码，则将从最大条码值的下一位继续生成。</span>
                                        <br />
                                        <br />
                                        <!-- 按钮部分 -->
                                        <div class="text-center btn-group text-align:center">
                                            <button type="button" style="float: left" class="btn-success" disabled="disabled" id="save" th:onclick="savebarcode()" >保存</button>
                                            <button type="button" class="btn-warning" onclick="location.reload()">重置</button>
                                            <button type="button" style="float: right" id="product" class="btn-info" th:onclick="generate()" ><span class="btn-info">为无条码商品生成条码</span></button>
                                            <button type="button" style="float: right" id="single" class="btn-info" th:onclick="generate()" ><span class="btn-info">为无条码单品生成条码</span></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <br>
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </section>

        </form>
    </div>
</div>
    <footer th:replace="common/footer::common_footer"></footer>
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
            <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
            <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
            <!-- Home tab content -->
            <div class="tab-pane" id="control-sidebar-home-tab">
                <h3 class="control-sidebar-heading">Recent Activity</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-birthday-cake bg-red"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                                <p>Will be 23 on April 24th</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-user bg-yellow"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Frodo Updated His Profile</h4>

                                <p>New phone +1(800)555-1234</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-envelope-o bg-light-blue"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Nora Joined Mailing List</h4>

                                <p>nora@example.com</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-file-code-o bg-green"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Cron Job 254 Executed</h4>

                                <p>Execution time 5 seconds</p>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

                <h3 class="control-sidebar-heading">Tasks Progress</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Custom Template Design
                                <span class="label label-danger pull-right">70%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Update Resume
                                <span class="label label-success pull-right">95%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-success" style="width: 95%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Laravel Integration
                                <span class="label label-warning pull-right">50%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-warning" style="width: 50%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Back End Framework
                                <span class="label label-primary pull-right">68%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-primary" style="width: 68%"></div>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

            </div>
            <!-- /.tab-pane -->
            <!-- Stats tab content -->
            <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
            <!-- /.tab-pane -->
            <!-- Settings tab content -->
            <div class="tab-pane" id="control-sidebar-settings-tab">
                <form method="post">
                    <h3 class="control-sidebar-heading">General Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Report panel usage
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Some information about this general settings option
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Allow mail redirect
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Other sets of options are available
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Expose author name in posts
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Allow the user to show his name in blog posts
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <h3 class="control-sidebar-heading">Chat Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Show me as online
                            <input type="checkbox" class="pull-right" checked>
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Turn off notifications
                            <input type="checkbox" class="pull-right">
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Delete chat history
                            <a href="javascript:void(0)" class="text-red pull-right"><i class="fa fa-trash-o"></i></a>
                        </label>
                    </div>
                    <!-- /.form-group -->
                </form>
            </div>
            <!-- /.tab-pane -->
        </div>
    </aside>
    <div class="control-sidebar-bg"></div>
</div>
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Slimscroll -->
<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- iCheck -->
<script src="../../plugins/iCheck/icheck.min.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="../../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Page Script -->
<script th:inline="javascript">
    var barcode =[[${barcode}]];
    var st=document.getElementById('static');
    st.checked=barcode.product_static;
    var product=document.getElementById('product');
    var single=document.getElementById('single');
    if(barcode.last_static==2){
        $("[name='barcodeItem'][value="+barcode.last_static+"]").prop("checked", "checked");
        $("#factoryCode").val(barcode.single_barCode_forward);
        $("#startCode").val(barcode.single_barCode_later.substring(0,4));
        product.style.display="none";
        single.style.display="inline";
    }
    else{
        $("[name='barcodeItem'][value="+barcode.last_static+"]").prop("checked", "checked");
        $("#factoryCode").val(barcode.product_barcode_forward);
        $("#startCode").val(barcode.product_barcode_later.substring(0,4));
        product.style.display="inline";
        single.style.display="none";
    }
    $("#save").removeAttr("disabled");

    // code 保存
    function savebarcode(){
        $.ajax({
            url:"/barcode/savebarcode",
            type:'POST',
            data:{
                _static:st.checked,
                factory:$("#factoryCode").val(),
                start:$("#startCode").val(),
                barcodeItem:$('input:radio:checked').val(),
            },
            success:function (data) {
                if (data.code == 1) {
                    window.location.href = "/setting/barcode_management";
                    alert("保存成功");
                } else {
                    alert(data.msg);
                }
            }
        })
    }

    // 位数判断
    function number() {
        var len8=$("#factoryCode").val().length;
        var len4=$("#startCode").val().length;
        if(0<len4&&len4<=4&&0<len8&&len8<=8){
            $("#save").removeAttr("disabled");
        }
        else{
            $("#save").attr({"disabled":"disabled"});
        }
    }

    //为无条码商品生成条码
    function generate(){
        var yu="";
        if(barcode.last_static==1){
            yu="商品";
        }
        else{
            yu="单品";
        }
        var r=confirm("即将为系统所有无条码的"+yu+"自动生成"+yu+"条码，是否确认继续");
        if(r==true)
            $.ajax({
                url:"/barcode/generate",
                type:'POST',
                data:{
                    barcodeItem:$('input:radio:checked').val(),
                },
                success:function (data) {
                    if (data >= 1) {
                        window.location.href = "/setting/barcode_management";
                        alert("操作成功，本次操作共补充了"+data+"个"+yu+"条码！");
                    } else {
                        if(data >= 0){
                            alert("系统不存在无条码"+yu+"！");
                        }
                        else{
                            alert("现有厂商识别码下的产品代码已用完，请配置新的厂商识别码");
                        }
                    }

                }
            })
    }
</script>
</body>
</html>